package com.lich.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import com.lich.entity.ClientLogin;
import com.lich.entity.graph.ClientAnalysis;
import com.lich.entity.vo.Result;
import com.lich.service.graph.ClientAnalysisService;
import com.lich.util.ExcelUtil;

/**
 * @description: 启动次数统计图表
 * @author: yuanyh   
 * @Time: 2016年9月7日
 */
@Controller
@RequestMapping("/login/times")
public class LoginTimesController {

	@Resource
	ClientAnalysisService clientAnalysisService;
	/**
	 * @description:日登陆次数
	 * @author: yuanyh 
	 * @Time: 2016年9月7日  
	 * @return
	 */
	@RequestMapping(value="/day", method = RequestMethod.POST)
	public ModelAndView  dayLoginTimesMethod(ClientAnalysis clientAnalysis){	 
		Result<ClientAnalysis> result = new Result<>();
		
		clientAnalysisService.findDayLoginTimes(clientAnalysis);
		
		if(clientAnalysis.getDataList().size()>0){
			result.setObject(clientAnalysis);
			result.setSuccess(true);
			result.setMessage("获取数据成功");
		}else{
			result.setSuccess(false);
			result.setMessage("无数据");
		}
		
		return new ModelAndView(new MappingJackson2JsonView(), "result", result);
	}
	/**
	 * @description:周登陆次数
	 * @author: yuanyh 
	 * @Time: 2016年9月14日  
	 * @param clientAnalysis
	 * @return
	 */
	@RequestMapping(value="/week", method = RequestMethod.POST)
	public ModelAndView  weekLoginTimesMethod(ClientAnalysis clientAnalysis){	 
		Result<ClientAnalysis> result = new Result<>();
		
		clientAnalysisService.findWeekLoginTimes(clientAnalysis);
		
		if(clientAnalysis.getDataList().size()>0){
			result.setObject(clientAnalysis);
			result.setSuccess(true);
			result.setMessage("获取数据成功");
		}else{
			result.setSuccess(false);
			result.setMessage("无数据");
		}
		return new ModelAndView(new MappingJackson2JsonView(), "result", result);
	}
	/**
	 * @description:月登陆次数
	 * @author: yuanyh 
	 * @Time: 2016年9月14日  
	 * @param clientAnalysis
	 * @return
	 */
	@RequestMapping(value="/month", method = RequestMethod.POST)
	public ModelAndView  monthLoginTimesMethod(ClientAnalysis clientAnalysis){	 
		Result<ClientAnalysis> result = new Result<>();
		
		clientAnalysisService.findMonthLoginTimes(clientAnalysis);
		
		if(clientAnalysis.getDataList().size()>0){
			result.setObject(clientAnalysis);
			result.setSuccess(true);
			result.setMessage("获取数据成功");
		}else{
			result.setSuccess(false);
			result.setMessage("无数据");
		}
		
		return new ModelAndView(new MappingJackson2JsonView(), "result", result);
	}
	@RequestMapping(value = "/export",method = {RequestMethod.POST,RequestMethod.GET})    
    public void exportExcel(HttpServletResponse response,ClientAnalysis clientAnalysis)     
    throws Exception {   
        List<ClientLogin> list = clientAnalysisService.findClientLoginByDate(clientAnalysis); 
        String[] header = {"产品uuid","用户登陆名","手机型号","分辨率","系统类型","系统版本","软件版本","省","市","登陆日期"};
        String[] colunm = {"productId","username","phoneModel","phoneResolution","osType","osVersion","appVersion","provincialName","cityName","loginTime"};
        HSSFWorkbook wb = new ExcelUtil<ClientLogin>().export(list,ClientLogin.class,header,colunm,response,"登陆信息");    
   }  
}
